<?php

namespace Transaccion\Controller\Service;

use Zend\Db\Adapter\Adapter;
use Componentes\Controller\UtilsArrayController;
use Transaccion\Model\Entity\Pensum;
use Transaccion\Controller\Service\GenericService;
use Transaccion\Model\Dao\PensumDAO;

//SERVICIO
class PensumService extends GenericService {

    /**
     * @var Zend\Db\Adapter\Adapter 
     */
    private $dbAdapter;
    private static $pensumService;

    /**
     * @param \Zend\Db\Adapter\Adapter $dbAdapter
     */
    private function __construct(Adapter $dbAdapter) {
        $this->dbAdapter = $dbAdapter;
    }

    public static function getInstance($adapter) {
        if (self::$pensumService == null) {
            self::$pensumService = new PensumService($adapter);
        }
        return self::$pensumService;
    }

    public function getPensumDao() {
        return PensumDAO::getInstance($this->dbAdapter);
    }

    /**
     * @param type $id
     * @return type
     */
    public function getRegistros($idEspecialidad) {
        $success = true;
        $data = $this->obtenerArrayMateriasSegunIdEspecialidad($idEspecialidad);
        return UtilsArrayController::organizarOutput($success, $data, null);
    }

    public function obtenerArrayMateriasSegunIdEspecialidad($idEspecialidad) {
        $registros = $this->getPensumDao()->getPensumPorEspecialidad($idEspecialidad);
        $data = UtilsArrayController::llenarData($registros);
        return $data;
    }

//------Retornan los objetos-------

    public function obtenerPensumSegunIdMateria($array, $idMateria) {
        $pensum = null;
        for ($i = 0; $i < count($array); $i++) {
            $idMateriaArray = $array[$i]['smateid'];
            if ($idMateriaArray == $idMateria){
                $pensum = new Pensum($array[$i]);
            }
        }
        return $pensum;
    }

//---------------------------------
}
